#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    const int INF=1e5+10;
    vector<vector<long long>> splitPainting(vector<vector<int>>& segments) {
        vector<long long> vec(INF);
        vector<vector<long long>> ret;
        for(auto it:segments)
        {
            vec[it[0]]+=it[2];
            vec[it[1]+1]-=it[2];
        }
        for(int i=1;i<INF;i++) vec[i]+=vec[i-1];
        int left=0;
        int right=0;
        int count=0;
        for(int i=1;i<INF;i++)
        {
            if(vec[i]&&count==0)
            {
                left=i;
                count=vec[i];
            }
            else
            {
                if(vec[i]!=vec[i-1])
                {
                    ret.push_back({left,i,count});
                    count=vec[i];
                    left=i;
                }
            }
        }
        return ret;
    }
};

int main()
{
    vector<vector<int>> vec={{1,4,5},{4,7,7},{1,7,9}};
    Solution so;
    so.splitPainting(vec);
    return 0;
}